﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Security.Cryptography;
using Aspose.Cells;
using System.IO;
using SHNOPData.SHNOPModel;
using LogSystem;
namespace SHNOPData.common
{
    public sealed partial class AppDBMng
    {
        public static string operate = "";
     

        #region 获取数据字典指定类型的内容列表
        /// <summary>
        /// 从数据字典获取指定类型的内容列表，可直接用于下拉列表框绑定内容使用，调用方式形如：
        /// GetZiDianContent(ZiDian.g_客户机房地址所属实际区域)
        /// </summary>
        /// <param name="boundObjStr">拼凑字符串，如:'分公司','加站属性'</param>
        /// <returns>返回DataSet，失败的情况下为 null，可直接赋值给下拉列表框的DataSource属性</returns>
        public static DataTable GetZiDianContent(string boundObjStr)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_GetDictionarySet";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@boundObjStr", boundObjStr);
                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, commandText, sp);
                if (ds != null)
                {
                    return ds.Tables[0];
                }
            }
            catch
            {
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;
        }
        #endregion

        #region 查询_网络规划_申请历史
        /// <summary>
        /// mtsp_查询_网络规划_申请历史
        /// </summary>
        /// <param name="totalcount"></param>
        /// <returns></returns>
        public static DataSet GetNTPlaning_HistoryList(Guid guihuaID)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_查询_网络规划_申请历史";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@规划ID", guihuaID);
                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, commandText, sp);
                if (ds != null)
                {
                    System.Web.HttpContext.Current.Session["historySession"] = ds;
                    return ds;

                }
            }
            catch
            {
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;
        }
        #endregion

        #region 查询所属方案列表
        public static  DataTable GetBelongScheme()
        {
             // 

            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string commandText = @"select  distinct(所属方案) 所属方案  
                                        from [MTNOH_SH_APP].[dbo].MTP_规划数据表  
                                        where 所属方案 <>'' 
                                        order by 所属方案 ";
             
                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText);
                if (ds != null)
                {
                    return ds.Tables[0];
                }
            }
            catch
            {
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;

        }
        public static DataTable GetTDBelongScheme()
        {
            // 

            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string commandText = @"select  distinct TD所属方案 AS 所属方案 
                                        from [MTNOH_SH_APP].[dbo].MTP_规划数据表  
                                        where TD所属方案 <>'' 
                                        order by TD所属方案 ";

                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, commandText);
                if (ds != null)
                {
                    return ds.Tables[0];
                }
            }
            catch
            {
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;

        }
#endregion
        #region 查询网络规划基础信息
        public static DataTable GetNTPlaningList(NTPlanSearchItem nTPlanSearchItem, ref int totalcount)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string Adv_longitude = nTPlanSearchItem.Adv_longitude == string.Empty 
                    ? null : nTPlanSearchItem.Adv_longitude;
                string Adv_latitude = nTPlanSearchItem.Adv_latitude == string.Empty 
                    ? null : nTPlanSearchItem.Adv_latitude;
                string commandText = "MTNOH_SH_APP.dbo.mtsp_查询_网络规划_信息列表";
                SqlParameter[] sp = new SqlParameter[18];
                sp[0] = new SqlParameter("@totalCount", totalcount);
                sp[0].Direction = ParameterDirection.Output;
                sp[1] = new SqlParameter("@简单或高级", nTPlanSearchItem.SimOrAdv);
                sp[2] = new SqlParameter("@查询类型", nTPlanSearchItem.Sim_SearchType);
                sp[3] = new SqlParameter("@查询内容", nTPlanSearchItem.Sim_SearchContent);
                sp[4] = new SqlParameter("@分公司", nTPlanSearchItem.Sim_CompanyIDS);
                sp[5] = new SqlParameter("@规划编号", nTPlanSearchItem.Adv_planningNum);
                sp[6] = new SqlParameter("@所属方案", nTPlanSearchItem.Adv_belongScheme);
                sp[7] = new SqlParameter("@加站属性", nTPlanSearchItem.Adv_jiaZhanPro);
                sp[8] = new SqlParameter("@加站类型", nTPlanSearchItem.Adv_jiaZhanType);
                sp[9] = new SqlParameter("@加站目的", nTPlanSearchItem.Adv_jiaZhanAim);
                sp[10] = new SqlParameter("@经度", Adv_longitude);
                sp[11] = new SqlParameter("@纬度", Adv_latitude);
                sp[12] = new SqlParameter("@规划频段", nTPlanSearchItem.Adv_channel);
                sp[13] = new SqlParameter("@环线信息", nTPlanSearchItem.Adv_huanXianInfo);
                sp[14] = new SqlParameter("@是否投诉", nTPlanSearchItem.Adv_isComplaint);
                sp[15] = new SqlParameter("@是否同址", nTPlanSearchItem.Adv_isSameAddr);
                sp[16] = new SqlParameter("@是否同站", nTPlanSearchItem.Adv_isSameZhan);
                sp[17] = new SqlParameter("@距离", nTPlanSearchItem.Adv_Distance);
                SqlDataAdapter ad = SqlHelper.ExecuteDataAdapter(conn, CommandType.StoredProcedure, commandText, sp);
                DataSet ds = new DataSet();
             
                ad.Fill(ds);
               
                totalcount = ConvertUtil.StringToInt(sp[0].Value);
                if(ds!=null)
                {
                    return ds.Tables[0];
                }
            }
            catch{
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;
        }
        #endregion

        #region 查询网络规划详细信息
        public static DataTable GetNTPlaningInfo(Guid PlanID)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_查询_网络规划_详细信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@PlanID", PlanID);
                SqlDataAdapter ad = SqlHelper.ExecuteDataAdapter(conn, CommandType.StoredProcedure, commandText, sp);
                DataSet ds = new DataSet();
                ad.Fill(ds);

                if (ds != null)
                {
                    return ds.Tables[0];
                }
            }
            catch
            {
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;
        }
        #endregion
        #region 分页查询网络规划基础信息
        public static DataTable GetNTPlaningListByPage(NTPlanSearchItem nTPlanSearchItem, ref int totalcount)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string Adv_longitude = nTPlanSearchItem.Adv_longitude == string.Empty
                    ? null : nTPlanSearchItem.Adv_longitude;
                string Adv_latitude = nTPlanSearchItem.Adv_latitude == string.Empty
                    ? null : nTPlanSearchItem.Adv_latitude;
                ///改为分页存储过程 by jianke 2012.9.28
                string commandText = "MTNOH_SH_APP.dbo.mtsp_分页查询_网络规划_信息列表";
                //string commandText = "MTNOH_SH_APP.dbo.mtsp_查询_网络规划_信息列表";
                //SqlParameter[] sp = new SqlParameter[17];
                SqlParameter[] sp = new SqlParameter[20];
                sp[0] = new SqlParameter("@totalCount", totalcount);
                sp[0].Direction = ParameterDirection.Output;
                sp[1] = new SqlParameter("@简单或高级", nTPlanSearchItem.SimOrAdv);
                sp[2] = new SqlParameter("@查询类型", nTPlanSearchItem.Sim_SearchType);
                sp[3] = new SqlParameter("@查询内容", nTPlanSearchItem.Sim_SearchContent);
                sp[4] = new SqlParameter("@分公司", nTPlanSearchItem.Sim_CompanyIDS);
                sp[5] = new SqlParameter("@规划编号", nTPlanSearchItem.Adv_planningNum);
                sp[6] = new SqlParameter("@所属方案", nTPlanSearchItem.Adv_belongScheme);
                sp[7] = new SqlParameter("@加站属性", nTPlanSearchItem.Adv_jiaZhanPro);
                sp[8] = new SqlParameter("@加站类型", nTPlanSearchItem.Adv_jiaZhanType);
                sp[9] = new SqlParameter("@加站目的", nTPlanSearchItem.Adv_jiaZhanAim);
                sp[10] = new SqlParameter("@经度", Adv_longitude);
                sp[11] = new SqlParameter("@纬度", Adv_latitude);
                sp[12] = new SqlParameter("@规划频段", nTPlanSearchItem.Adv_channel);
                sp[13] = new SqlParameter("@环线信息", nTPlanSearchItem.Adv_huanXianInfo);
                sp[14] = new SqlParameter("@是否投诉", nTPlanSearchItem.Adv_isComplaint);
                sp[15] = new SqlParameter("@是否同址", nTPlanSearchItem.Adv_isSameAddr);
                sp[16] = new SqlParameter("@是否同站", nTPlanSearchItem.Adv_isSameZhan);
                sp[17] = new SqlParameter("@距离", nTPlanSearchItem.Adv_Distance);
                sp[18] = new SqlParameter("@currentpage", nTPlanSearchItem.Currentpage);
                sp[19] = new SqlParameter("@pagesize", nTPlanSearchItem.PageSize);
                SqlDataAdapter ad = SqlHelper.ExecuteDataAdapter(conn, CommandType.StoredProcedure, commandText, sp);
                DataSet ds = new DataSet();
                ad.Fill(ds);
                // ad.Fill(ds, nTPlanSearchItem.BeginRecod, nTPlanSearchItem.PageSize, "信息列表");
                totalcount = ConvertUtil.StringToInt(sp[0].Value);
                if (ds != null)
                {
                    return ds.Tables[0];
                }
            }
            catch
            {
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
            return null;
        }
        #endregion

        #region 新增或修改网络规划
        public static bool InsertOrEditPlan(NTPlanBase oldNTPlanBase, NTPlanBase newNTPlanBase)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_编辑_网络规划_基础信息";
                SqlParameter[] sp = new SqlParameter[32];
                sp[0] = new SqlParameter("@规划ID" , newNTPlanBase.ntplanID);
                sp[1] = new SqlParameter("@FK_D_加站属性ID" , newNTPlanBase.jiaZhanProID);
                sp[2] = new SqlParameter("@是否同址", newNTPlanBase.isSameAddr == 0 ? (int?)null : (newNTPlanBase.isSameAddr == 2 ? 0 : 1));
                sp[3] = new SqlParameter("@FK_D_分公司ID" , newNTPlanBase.companyID);
                sp[4] = new SqlParameter("@所属方案" , newNTPlanBase.belongScheme);
                sp[5] = new SqlParameter("@是否调整" , newNTPlanBase.isTiaoZheng);
                sp[6] = new SqlParameter("@是否投诉" , newNTPlanBase.isComplaint);
                sp[7] = new SqlParameter("@规划经度" , newNTPlanBase.longitude);
                sp[8] = new SqlParameter("@规划纬度" , newNTPlanBase.latitude);
                sp[9] = new SqlParameter("@FK_D_环线信息ID" , newNTPlanBase.huanXianInfoID);
                sp[10] = new SqlParameter("@FK_D_设备厂商ID" , newNTPlanBase.deviceFacturerID);
                sp[11] = new SqlParameter("@FK_D_规划频段ID" , newNTPlanBase.channelID);
                sp[12] = new SqlParameter("@900M规划配置" , newNTPlanBase._900PlanPeiZhi);
                sp[13] = new SqlParameter("@900M配置" , newNTPlanBase._900PeiZhi);
                sp[14] = new SqlParameter("@1800M规划配置" , newNTPlanBase._1800PlanPeiZhi);
                sp[15] = new SqlParameter("@1800M配置" , newNTPlanBase._1800PeiZhi);
                sp[16] = new SqlParameter("@规划总配置" , newNTPlanBase.planPeiZhiSum);
                sp[17] = new SqlParameter("@900M规划端口" , newNTPlanBase._900PlanPort);
                sp[18] = new SqlParameter("@1800规划端口" , newNTPlanBase._1800PlanPort);
                sp[19] = new SqlParameter("@规划总端口数" , newNTPlanBase.planPortSum);
                sp[20] = new SqlParameter("@FK_D_加站类型ID" , newNTPlanBase.jiaZhanTypeID);
                sp[21] = new SqlParameter("@加站目的" , newNTPlanBase.jiaZhanAim);
                sp[22] = new SqlParameter("@规划编号" , newNTPlanBase.planningNum);
                sp[23] = new SqlParameter("@协同平台工单号" , newNTPlanBase.XieTongNum);
                sp[24] = new SqlParameter("@规划挂高", newNTPlanBase.PlanGuaGao);
                sp[25] = new SqlParameter("@TD规划配置" , newNTPlanBase.TDPlanPeiZhi);
                sp[26] = new SqlParameter("@TD配置" , newNTPlanBase.TDPeiZhi);
                sp[27] = new SqlParameter("@TD规划端口" , newNTPlanBase.TDPlanDuanKou);
                sp[28] = new SqlParameter("@TD规划编号" , newNTPlanBase.TDPlanningNum);
                sp[29] = new SqlParameter("@TD所属方案", newNTPlanBase.TDBelongScheme);
                sp[30] = new SqlParameter("@FK_D_TD设备厂商ID", newNTPlanBase.TDdeviceFacturerID);

                sp[31] = new SqlParameter("@outResult", Guid.Empty);
                sp[31].Direction = ParameterDirection.Output;
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);



                string idStr = parameterCollection["@outResult"].Value.ToString();

                if (idStr.Length != 0)
                {
                    newNTPlanBase.ntplanID = (Guid)parameterCollection["@outResult"].Value;
                }
                List<NTPlanBase> list = new List<NTPlanBase>();
                list.Add( oldNTPlanBase);
                list.Add(newNTPlanBase);

                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(OperateLogWrite.LogNTPlanBase));
                thread.Start(list);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 新增或修改站点申请信息
      /// <summary>
        /// 新增或修改站点申请信息
      /// </summary>
      /// <param name="oldZhanDianInfo"></param>
      /// <param name="newZhanDianInfo"></param>
      /// <returns></returns>
        public static bool InsertOrEditZhanDianInfo(ZhanDianInfo oldZhanDianInfo, ZhanDianInfo newZhanDianInfo)
        {
            SqlConnection conn = ConnMng.GetConnection();

           
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_编辑_网络规划_站点申请信息";
                SqlParameter[] sp = new SqlParameter[47];
                sp[0] = new SqlParameter("@站点ID",  newZhanDianInfo.zhanDianID);
                sp[1] = new SqlParameter("@FK_规划_ID",  newZhanDianInfo.guiHuaID);
                sp[2] = new SqlParameter("@是否已上一站一单", newZhanDianInfo.isZhanDan == 0 ? (int?)null : (newZhanDianInfo.isZhanDan == 2 ? 0 : 1));
                sp[3] = new SqlParameter("@工单号", newZhanDianInfo.orderNum);

                sp[4] = new SqlParameter("@FK_D_是否同意", newZhanDianInfo.isAgreeId);
                sp[5] = new SqlParameter("@是否符合站址偏差标准", newZhanDianInfo.isFuHeZhanCha == 0 ? (int?)null : (newZhanDianInfo.isFuHeZhanCha == 2 ? 0 : 1));
                sp[6] = new SqlParameter("@工单回复内容",  newZhanDianInfo.ReplyContent);
                sp[7] = new SqlParameter("@回复人员",  newZhanDianInfo.ReplyMan);
                sp[8] = new SqlParameter("@物理站点名",  newZhanDianInfo.PhysicalSite);
                sp[9] = new SqlParameter("@工单回复日期",  newZhanDianInfo.ReplyDate);
                sp[10] = new SqlParameter("@后续措施类型",  newZhanDianInfo.HouXuType);
                sp[11] = new SqlParameter("@后续措施编号",  newZhanDianInfo.HouXuNum);
                sp[12] = new SqlParameter("@后续措施所属方案",  newZhanDianInfo.HouXuFangAn);
                sp[13] = new SqlParameter("@后续措施地址",  newZhanDianInfo.HouXuAddr);
                sp[14] = new SqlParameter("@后续措施经度",  newZhanDianInfo.HouXulongitude);
                sp[15] = new SqlParameter("@后续措施纬度",  newZhanDianInfo.HouXulatitude);
                sp[16] = new SqlParameter("@后续措施挂高",  newZhanDianInfo.HouXuGuaGao);
                sp[17] = new SqlParameter("@同意比例",  newZhanDianInfo.agreeScale);
                sp[18] = new SqlParameter("@实际经度",  newZhanDianInfo.realityLongitude);
                sp[19] = new SqlParameter("@实际纬度",  newZhanDianInfo.realityLatitude);
                sp[20] = new SqlParameter("@与规划经纬度偏差距离",  newZhanDianInfo.howFarToPlanning);
                sp[21] = new SqlParameter("@实际高度",  newZhanDianInfo.realityHeight);
                sp[22] = new SqlParameter("@地址",  newZhanDianInfo.address);
                sp[23] = new SqlParameter("@规划方向角",  newZhanDianInfo.planningFXJiao);
                sp[24] = new SqlParameter("@规划配置",  newZhanDianInfo.planningPZ);
                sp[25] = new SqlParameter("@规划机械倾角",  newZhanDianInfo.planningJXQJiao);
                sp[26] = new SqlParameter("@规划电子倾角",  newZhanDianInfo.planningDZQJiao);
                sp[27]=new SqlParameter("@outResult",Guid.Empty);
                sp[27].Direction = ParameterDirection.Output;
                sp[28] = new SqlParameter("@TD工单号", newZhanDianInfo.TDOrderNum);
                sp[29] = new SqlParameter("@FK_D_TD是否同意", newZhanDianInfo.TDIsAgreeId);
                sp[30] = new SqlParameter("@TD是否符合站址偏差标准", newZhanDianInfo.TDIsFuHeZhanCha 
                    == 0 ? (int?)null : (newZhanDianInfo.TDIsFuHeZhanCha == 2 ? 0 : 1));
                sp[31] = new SqlParameter("@TD同意比例", newZhanDianInfo.TDAgreeScale);
                sp[32] = new SqlParameter("@TD工单回复内容", newZhanDianInfo.TDReplyContent);
                sp[33] = new SqlParameter("@TD规划方向角", newZhanDianInfo.TDPlanningFXJiao);
                sp[34] = new SqlParameter("@TD规划配置", newZhanDianInfo.TDPlanningPZ);
                sp[35] = new SqlParameter("@TD规划机械倾角", newZhanDianInfo.TDPlanningJXQJiao);
                sp[36] = new SqlParameter("@TD规划电子倾角", newZhanDianInfo.TDPlanningDZQJiao);
                sp[37] = new SqlParameter("@TD后续措施类型", newZhanDianInfo.TDHouXuType);
                sp[38] = new SqlParameter("@TD后续措施编号", newZhanDianInfo.TDHouXuNum);
                sp[39] = new SqlParameter("@TD后续措施所属方案", newZhanDianInfo.TDHouXuFangAn);
                sp[40] = new SqlParameter("@TD后续措施地址", newZhanDianInfo.TDHouXuAddr);
                sp[41] = new SqlParameter("@TD后续措施经度", newZhanDianInfo.TDHouXulongitude);
                sp[42] = new SqlParameter("@TD后续措施纬度", newZhanDianInfo.TDHouXulatitude);
                sp[43] = new SqlParameter("@TD后续措施挂高", newZhanDianInfo.TDHouXuGuaGao);
                sp[44] = new SqlParameter("@与规划高度偏差", newZhanDianInfo.howFarToPlanHeight);
                sp[45] = new SqlParameter("@后续措施相关文号", newZhanDianInfo.HouXuFilesNum);
                sp[46] = new SqlParameter("@TD后续措施相关文号", newZhanDianInfo.TDHouXuFilesNum);


                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);

                

                string idStr=parameterCollection["@outResult"].Value.ToString();

                if (idStr.Length!=0)
                {

                    newZhanDianInfo.zhanDianID = (Guid)parameterCollection["@outResult"].Value;
                }
                List<ZhanDianInfo> list = new List<ZhanDianInfo>();
                list.Add(oldZhanDianInfo);
                list.Add(newZhanDianInfo);
            
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(OperateLogWrite.LogZhanDianInfo));
                thread.Start(list);

                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 新增或修改端口申请信息
        /// <summary>
        /// 新增或修改端口申请信息
        /// </summary>
        /// <param name="duanKouID"></param>
        /// <param name="guiHuaID"></param>
        /// <param name="isFenpei"></param>
        /// <param name="_900ShenqingNum"></param>
        /// <param name="_900FenpeiNum"></param>
        /// <param name="_900Reason"></param>
        /// <param name="_900FenpeiDate"></param>
        /// <param name="_1800ShenqingNum"></param>
        /// <param name="_1800FenpeiNum"></param>
        /// <param name="_1800Reason"></param>
        /// <param name="_1800FenpeiDate"></param>
        /// <param name="DuanKouTotalNum"></param>
        /// <returns></returns>
        public static bool InsertOrEditDuanKouInfo(PortInfo oldPortInfo, PortInfo newPortInfo)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_编辑_网络规划_端口申请信息";
                SqlParameter[] sp = new SqlParameter[17];
                sp[0] = new SqlParameter("@端口ID" , newPortInfo.duanKouID);
                sp[1] = new SqlParameter("@FK_规划_ID" , newPortInfo.guiHuaID);
                sp[2] = new SqlParameter("@是否已分配端口", newPortInfo.isFenpei == 0 ? (int?)null : (newPortInfo.isFenpei == 2 ? 0 : 1));
                sp[3] = new SqlParameter("@900M站点申请端口数" , newPortInfo._900ShenqingNum);
                sp[4] = new SqlParameter("@900M站点端口分配数" , newPortInfo._900FenpeiNum);
                sp[5] = new SqlParameter("@900M未完成端口分配原因" , newPortInfo._900Reason);
                sp[6] = new SqlParameter("@900M端口申请日期" , newPortInfo._900FenpeiDate);
                sp[7] = new SqlParameter("@1800M站点申请端口数" , newPortInfo._1800ShenqingNum);
                sp[8] = new SqlParameter("@1800M站点端口分配数" , newPortInfo._1800FenpeiNum);
                sp[9] = new SqlParameter("@1800M未完成端口分配原因" , newPortInfo._1800Reason);
                sp[10] = new SqlParameter("@1800M端口申请日期" , newPortInfo._1800FenpeiDate);
                sp[11] = new SqlParameter("@分配端口总数" , newPortInfo.DuanKouTotalNum);
                sp[12] = new SqlParameter("@TD站点申请端口数" , newPortInfo.TDShenqingNum);
                sp[13] = new SqlParameter("@TD站点端口分配数" , newPortInfo.TDFenPeiNum);
                sp[14] = new SqlParameter("@TD端口申请日期" , newPortInfo.TDShenqingDate);
                sp[15] = new SqlParameter("@TD未完成端口分配原因" , newPortInfo.TDReason);
                sp[16] = new SqlParameter("@outResult", Guid.Empty);
                sp[16].Direction = ParameterDirection.Output;
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);



                string idStr = parameterCollection["@outResult"].Value.ToString();

                if (idStr.Length != 0)
                {
                    newPortInfo.duanKouID = (Guid)parameterCollection["@outResult"].Value;
                }
                List<PortInfo> list = new List<PortInfo>();
                list.Add(oldPortInfo);
                list.Add(newPortInfo);

                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(OperateLogWrite.LogPortInfo));
                thread.Start(list);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 新增或修改频率申请信息
        /// <summary>
        /// 新增或修改频率申请信息
        /// </summary>
        /// <param name="pinLvID"></param>
        /// <param name="guiHuaID"></param>
        /// <param name="isShenqing"></param>
        /// <param name="is900Shenqing"></param>
        /// <param name="is900Fenpei"></param>
        /// <param name="_900Reason"></param>
        /// <param name="_900GuihuaDate"></param>
        /// <param name="_900Gongdan"></param>
        /// <param name="is1800Shenqing"></param>
        /// <param name="is1800Fenpei"></param>
        /// <param name="_1800Reason"></param>
        /// <param name="_1800GuihuaDate"></param>
        /// <param name="_1800Gongdan"></param>
        /// <returns></returns>
        public static bool InsertOrEditPinLvInfo(PinLvInfo oldPinLvInfo, PinLvInfo newPinLvInfo)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                 
                string commandText = "MTNOH_SH_APP.dbo.mtsp_编辑_网络规划_频率申请信息";
                SqlParameter[] sp = new SqlParameter[19];
                sp[0] = new SqlParameter("@频率ID" , newPinLvInfo. pinLvID);
                sp[1] = new SqlParameter("@FK_规划_ID" , newPinLvInfo. guiHuaID);
                sp[2] = new SqlParameter("@是否频率申请", newPinLvInfo.isShenqing 
                    == 0 ? (int?)null : (newPinLvInfo.isShenqing == 2 ? 0 : 1));
                sp[3] = new SqlParameter("@900M是否频率申请", newPinLvInfo.is900Shenqing
                    == 0 ? (int?)null : (newPinLvInfo.is900Shenqing == 2 ? 0 : 1));
                sp[4] = new SqlParameter("@900M是否频率分配", newPinLvInfo.is900Fenpei
                    == 0 ? (int?)null : (newPinLvInfo.is900Fenpei == 2 ? 0 : 1));
                sp[5] = new SqlParameter("@FK_D_900M未分配原因_ID", newPinLvInfo._900MReasonID);
                sp[6] = new SqlParameter("@900M频率规划日期" , newPinLvInfo. _900GuihuaDate);
                sp[7] = new SqlParameter("@900M工单号" , newPinLvInfo. _900Gongdan);
                sp[8] = new SqlParameter("@1800M是否频率申请", newPinLvInfo.is1800Shenqing
                    == 0 ? (int?)null : (newPinLvInfo.is1800Shenqing == 2 ? 0 : 1));
                sp[9] = new SqlParameter("@1800M是否频率分配", newPinLvInfo.is1800Fenpei
                    == 0 ? (int?)null : (newPinLvInfo.is1800Fenpei == 2 ? 0 : 1));
                sp[10] = new SqlParameter("@FK_D_1800M未分配原因_ID", newPinLvInfo._1800MReasonID);
                sp[11] = new SqlParameter("@1800M频率规划日期" , newPinLvInfo. _1800GuihuaDate);
                sp[12] = new SqlParameter("@1800M工单号" , newPinLvInfo. _1800Gongdan);
                sp[13] = new SqlParameter("@TD是否频率申请", newPinLvInfo.isTDShengqing
                    == 0 ? (int?)null : (newPinLvInfo.isTDShengqing == 2 ? 0 : 1));
                sp[14] = new SqlParameter("@TD是否频率分配", newPinLvInfo.isTDFenPei
                    == 0 ? (int?)null : (newPinLvInfo.isTDFenPei == 2 ? 0 : 1));
                sp[15] = new SqlParameter("@TD频率规划日期" , newPinLvInfo. TDGuihuaDate);
                sp[16] = new SqlParameter("@FK_D_TD未分配原因_ID", newPinLvInfo.TDReasonID);
                sp[17] = new SqlParameter("@TD工单号" , newPinLvInfo. TDGongdanNum);
                sp[18] = new SqlParameter("@outResult", Guid.Empty);
                sp[18].Direction = ParameterDirection.Output;
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);



                string idStr = parameterCollection["@outResult"].Value.ToString();

                if (idStr.Length != 0)
                {
                    newPinLvInfo.pinLvID = (Guid)parameterCollection["@outResult"].Value;
                }
                List<PinLvInfo> list = new List<PinLvInfo>();
                list.Add(oldPinLvInfo);
                list.Add(newPinLvInfo);

                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(OperateLogWrite.LogPinLvInfo));
                thread.Start(list);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 新增或修改入网申请信息
        /// <summary>
        /// 新增或修改入网申请信息
        /// </summary>
        /// <param name="ruWangID"></param>
        /// <param name="guiHuaID"></param>
        /// <param name="RuWangQingKuang"></param>
        /// <param name="RuWangDate"></param>
        /// <param name="GWangName"></param>
        /// <param name="DWangName"></param>
        /// <param name="isComplete"></param>
        /// <param name="isRuWang"></param>
        /// <param name="RuWangReason"></param>
        /// <param name="_900ShenqingNum"></param>
        /// <param name="_1800ShenqingNum"></param>
        /// <param name="totalPinNum"></param>
        /// <param name="_900DuanKouNum"></param>
        /// <param name="_1800DuanKouNum"></param>
        /// <param name="totalDuankouNum"></param>
        /// <returns></returns>
        public static bool InsertOrEditRuWangInfo(InNetInfo oldInNetInfo, InNetInfo newInNetInfo)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                 
                string commandText = "MTNOH_SH_APP.dbo.mtsp_编辑_网络规划_入网申请信息";
                SqlParameter[] sp = new SqlParameter[21];
                sp[0] = new SqlParameter("@入网ID", newInNetInfo. ruWangID);
                sp[1] = new SqlParameter("@FK_规划_ID", newInNetInfo. guiHuaID);
                sp[2] = new SqlParameter("@物理点入网情况", newInNetInfo. RuWangQingKuang);
                sp[3] = new SqlParameter("@物理点入网时间", newInNetInfo. RuWangDate);
                sp[4] = new SqlParameter("@G网站名", newInNetInfo. GWangName);
                sp[5] = new SqlParameter("@D网站名", newInNetInfo. DWangName);
                sp[6] = new SqlParameter("@是否完成规划评估", newInNetInfo.isComplete == 0 ? (int?)null : (newInNetInfo.isComplete == 2 ? 0 : 1));
                sp[7] = new SqlParameter("@是否部分入网", newInNetInfo.isRuWang == 0 ? (int?)null : (newInNetInfo.isRuWang == 2 ? 0 : 1));
                sp[8] = new SqlParameter("@FK_D_部分入网原因ID", newInNetInfo.RuWangReasonID);
                sp[9] = new SqlParameter("@900M入网载频数", newInNetInfo. _900ShenqingNum);
                sp[10] = new SqlParameter("@1800M入网载频数", newInNetInfo. _1800ShenqingNum);
                sp[11] = new SqlParameter("@入网总载频数", newInNetInfo. totalPinNum);
                sp[12] = new SqlParameter("@900M入网端口数", newInNetInfo. _900DuanKouNum);
                sp[13] = new SqlParameter("@1800M入网端口数", newInNetInfo. _1800DuanKouNum);
                sp[14] = new SqlParameter("@入网总端口数", newInNetInfo. totalDuankouNum);
                sp[15] = new SqlParameter("@T网站名", newInNetInfo. TWangName);
                sp[16] = new SqlParameter("@TD入网载频数", newInNetInfo. TDPinNum);
                sp[17] = new SqlParameter("@TD入网端口数", newInNetInfo.TDDuanKouNum);
                sp[18] = new SqlParameter("@部分入网后续跟踪", newInNetInfo.TDPartInNetEd);
                sp[19] = new SqlParameter("@完成日期", newInNetInfo.TDCompleteDate);
                sp[20] = new SqlParameter("@outResult", Guid.Empty);
                sp[20].Direction = ParameterDirection.Output;
               
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);



                string idStr = parameterCollection["@outResult"].Value.ToString();
                if (idStr.Length != 0)
                {
                    newInNetInfo.ruWangID = (Guid)parameterCollection["@outResult"].Value;
                }
                List<InNetInfo> list = new List<InNetInfo>();
                list.Add(oldInNetInfo);
                list.Add(newInNetInfo);

                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(OperateLogWrite.LogInNetInfo));
                thread.Start(list);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 删除规划基础信息
        public static bool DeleteNTPlanInfo(string guihuaid)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_删除_网络规划_全部信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@规划ID", guihuaid);
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);
                LogInfo loginfo = new LogInfo(operate,new Guid(guihuaid), OperateType.网络规划, new Guid(guihuaid), LogAction.删除, "删除一条网络规划记录");
                AddOperateLog(loginfo);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 删除站点信息
        public static bool DeleteZhanDianInfo(string guihuaID,string zhandianid)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_删除_网络规划_站点申请信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@站点ID", zhandianid);
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);
                LogInfo loginfo = new LogInfo(operate, new Guid(guihuaID), OperateType.站点, new Guid(zhandianid), LogAction.删除, "删除一条站点记录");
                AddOperateLog(loginfo);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 删除端口信息
        public static bool DeleteDuanKouInfo(string guihuaID,string duankouid)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_删除_网络规划_端口申请信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@端口ID", duankouid);
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);

                LogInfo loginfo = new LogInfo(operate, new Guid(guihuaID), OperateType.端口, new Guid(duankouid), LogAction.删除, "删除一条端口记录");
                AddOperateLog(loginfo);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 删除频率信息
        public static bool DeletePinLvInfo(string guihuaID,string pinlvid)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_删除_网络规划_频率申请信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@频率ID", pinlvid);
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);
                LogInfo loginfo = new LogInfo(operate, new Guid(guihuaID), OperateType.频率, new Guid(pinlvid), LogAction.删除, "删除一条频率 记录");
                AddOperateLog(loginfo);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 删除入网信息
        public static bool DeleteRuWangInfo(string guihuaID,string ruwangid)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_删除_网络规划_入网申请信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@入网ID", ruwangid);
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);
                LogInfo loginfo = new LogInfo(operate, new Guid(guihuaID), OperateType.入网, new Guid(ruwangid), LogAction.删除, "删除一条入网记录");
                AddOperateLog(loginfo);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion


        #region 用户登录
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="loginId">登陆用户名</param>
        /// <param name="password">密码</param>
        /// <param name="ret">登陆结果：0、成功；-1、数据访问失败；-2、用户名错误或不存在；-3、登录口令错误</param>
        /// <returns></returns>
        public static DataSet IsValid_InternalUser_v2(string loginId, string password, ref int ret)
        {
            byte[] result = Encoding.Default.GetBytes(password);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] output = md5.ComputeHash(result);
            string pwd = BitConverter.ToString(output).Replace("-", "");
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                LogBll.LogWebAppInfo("数据库连接失败。");
                return null;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_查询_登录用户信息";
                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@LoginID", loginId);
                SqlDataAdapter ad = SqlHelper.ExecuteDataAdapter(conn, CommandType.StoredProcedure, commandText, sp);
                ad.TableMappings.Add("Table", "用户信息");
                ad.TableMappings.Add("Table1", "用户角色");
                DataSet ds = new DataSet();
                ad.Fill(ds);

                DataTable dtUser = ds.Tables["用户信息"];
                if (dtUser == null)
                {
                    ret = -1;
                }
                else if (dtUser.Rows.Count == 0)
                {
                    ret = -2;
                }
                else
                {
                    if (pwd != dtUser.Rows[0]["Password"].ToString())
                    {
                        ret = -3;
                    }
                }
                return ds;
            }
            catch (Exception e)
            {
                LogBll.LogWebAppInfo("用户登录", e);
                ret = -1;
                return null;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 修改规划详细信息
        /// <summary>
        /// 网规详细信息初始化存储过程参数
        /// </summary>
        /// <param name="newNTPlanDetail"></param>
        /// <returns></returns>
        private static SqlParameter[] GetNTPlanDetailParams( NTPlanDetail newNTPlanDetail)
        {
            NTPlanBase ntPlanBase=newNTPlanDetail.ntPlanBase;
            ZhanDianInfo zhanDianInfo=newNTPlanDetail.zhanDianInfo;
            PortInfo portInfo=newNTPlanDetail.portInfo;
            PinLvInfo pinLvInfo=newNTPlanDetail.pinLvInfo;
            InNetInfo inNetInfo = newNTPlanDetail.inNetInfo;

            #region 网络规划基本信息
            int columns = 0;
            SqlParameter[] sp = new SqlParameter[133];

            sp[columns++] = new SqlParameter("@规划ID", ntPlanBase.ntplanID);
            sp[columns++] = new SqlParameter("@FK_D_加站属性ID", ntPlanBase. jiaZhanProID);
            sp[columns++] = new SqlParameter("@是否同址", ntPlanBase.isSameAddr == 0 ? (int?)null : (ntPlanBase.isSameAddr == 2 ? 0 : 1));
            sp[columns++] = new SqlParameter("@FK_D_分公司ID", ntPlanBase.companyID);
            sp[columns++] = new SqlParameter("@所属方案", ntPlanBase.belongScheme);
            sp[columns++] = new SqlParameter("@是否调整", ntPlanBase.isTiaoZheng);
            sp[columns++] = new SqlParameter("@是否投诉", ntPlanBase.isComplaint);
            sp[columns++] = new SqlParameter("@规划经度", ntPlanBase.longitude);
            sp[columns++] = new SqlParameter("@规划纬度", ntPlanBase.latitude);
            sp[columns++] = new SqlParameter("@FK_D_环线信息ID", ntPlanBase.huanXianInfoID);
            sp[columns++] = new SqlParameter("@FK_D_设备厂商ID", ntPlanBase.deviceFacturerID);
            sp[columns++] = new SqlParameter("@FK_D_规划频段ID", ntPlanBase.channelID);
            sp[columns++] = new SqlParameter("@900M规划配置", ntPlanBase._900PlanPeiZhi);
            sp[columns++] = new SqlParameter("@900M配置", ntPlanBase._900PeiZhi);
            sp[columns++] = new SqlParameter("@1800M规划配置", ntPlanBase._1800PlanPeiZhi);
            sp[columns++] = new SqlParameter("@1800M配置", ntPlanBase._1800PeiZhi);
            sp[columns++] = new SqlParameter("@规划总配置", ntPlanBase.planPeiZhiSum);
            sp[columns++] = new SqlParameter("@900M规划端口", ntPlanBase._900PlanPort);
            sp[columns++] = new SqlParameter("@1800规划端口", ntPlanBase._1800PlanPort);
            sp[columns++] = new SqlParameter("@规划总端口数", ntPlanBase.planPortSum);
            sp[columns++] = new SqlParameter("@FK_D_加站类型ID", ntPlanBase.jiaZhanTypeID);
            sp[columns++] = new SqlParameter("@加站目的", ntPlanBase.jiaZhanAim);
            sp[columns++] = new SqlParameter("@规划编号", ntPlanBase.planningNum);
            sp[columns++] = new SqlParameter("@协同平台工单号", ntPlanBase.XieTongNum);
            sp[columns++] = new SqlParameter("@规划挂高", ntPlanBase.PlanGuaGao);
            sp[columns++] = new SqlParameter("@TD规划配置", ntPlanBase.TDPlanPeiZhi);
            sp[columns++] = new SqlParameter("@TD配置", ntPlanBase.TDPeiZhi);
            sp[columns++] = new SqlParameter("@TD规划端口", ntPlanBase.TDPlanDuanKou);
            sp[columns++] = new SqlParameter("@TD规划编号", ntPlanBase.TDPlanningNum);
            sp[columns++] = new SqlParameter("@TD所属方案", ntPlanBase.TDBelongScheme);
            sp[columns++] = new SqlParameter("@FK_D_TD设备厂商ID", ntPlanBase.TDdeviceFacturerID);
            #endregion
            #region 站点信息
            if (zhanDianInfo==null)
            {
                 sp[columns++]= new SqlParameter("@站点ID", null);
                 sp[columns++] = new SqlParameter("@是否已上一站一单", (int?)null);
                 sp[columns++]= new SqlParameter("@工单号", null);
                 sp[columns++]= new SqlParameter("@FK_D_是否同意", null);
                 sp[columns++] = new SqlParameter("@是否符合站址偏差标准", (int?)null);
                 sp[columns++]= new SqlParameter("@工单回复内容", null);
                 sp[columns++]= new SqlParameter("@回复人员", null);
                 sp[columns++]= new SqlParameter("@物理站点名", null);
                 sp[columns++]= new SqlParameter("@工单回复日期",null);
                 sp[columns++]= new SqlParameter("@后续措施类型", null);
                 sp[columns++]= new SqlParameter("@后续措施编号", null);
                 sp[columns++]= new SqlParameter("@后续措施所属方案", null);
                 sp[columns++]= new SqlParameter("@后续措施地址", null);
                 sp[columns++] = new SqlParameter("@后续措施经度", (int?)null);
                 sp[columns++] = new SqlParameter("@后续措施纬度", (int?)null);
                 sp[columns++]= new SqlParameter("@后续措施挂高", null);
                 sp[columns++] = new SqlParameter("@同意比例", (float?)null);
                 sp[columns++] = new SqlParameter("@实际经度", (int?)null);
                 sp[columns++] = new SqlParameter("@实际纬度", (int?)null);
                 sp[columns++] = new SqlParameter("@与规划经纬度偏差距离", (int?)null);
                 sp[columns++] = new SqlParameter("@与规划高度偏差", (int?)null);
                 sp[columns++] = new SqlParameter("@实际高度", (int?)null);
                 sp[columns++]= new SqlParameter("@地址", null);
                 sp[columns++] = new SqlParameter("@规划方向角", (int?)null);
                 sp[columns++] = new SqlParameter("@规划配置", (int?)null);
                 sp[columns++] = new SqlParameter("@规划机械倾角", (int?)null);
                 sp[columns++] = new SqlParameter("@规划电子倾角", (int?)null);
                 sp[columns++] = new SqlParameter("@后续措施相关文号", null);
                 sp[columns++] = new SqlParameter("@TD后续措施相关文号", null);

                 sp[columns++] = new SqlParameter("@TD工单号_ZD", null);
                 sp[columns++] = new SqlParameter("@FK_D_TD是否同意", null);
                 sp[columns++] = new SqlParameter("@TD是否符合站址偏差标准", null);
                 sp[columns++] = new SqlParameter("@TD同意比例", (float?)null);
                 sp[columns++] = new SqlParameter("@TD工单回复内容", null);
                 sp[columns++] = new SqlParameter("@TD规划方向角", null);
                 sp[columns++] = new SqlParameter("@TD规划配置_ZD", null);
                 sp[columns++] = new SqlParameter("@TD规划机械倾角", null);
                 sp[columns++] = new SqlParameter("@TD规划电子倾角", null);
                 sp[columns++] = new SqlParameter("@TD后续措施类型", null);
                 sp[columns++] = new SqlParameter("@TD后续措施编号", null);
                 sp[columns++] = new SqlParameter("@TD后续措施所属方案", null);
                 sp[columns++] = new SqlParameter("@TD后续措施地址", null);
                 sp[columns++] = new SqlParameter("@TD后续措施经度", null);
                 sp[columns++] = new SqlParameter("@TD后续措施纬度", null);
                 sp[columns++] = new SqlParameter("@TD后续措施挂高", null);
                
            } 
            else
            {
                sp[columns++]= new SqlParameter("@站点ID", zhanDianInfo.zhanDianID);
                sp[columns++] = new SqlParameter("@是否已上一站一单", zhanDianInfo.isZhanDan == 0 ? (int?)null : (zhanDianInfo.isZhanDan == 2 ? 0 : 1));
                sp[columns++]= new SqlParameter("@工单号", zhanDianInfo.orderNum);
                sp[columns++]= new SqlParameter("@FK_D_是否同意", zhanDianInfo.isAgreeId);
                sp[columns++] = new SqlParameter("@是否符合站址偏差标准", zhanDianInfo.isFuHeZhanCha == 0 ? (int?)null : (zhanDianInfo.isFuHeZhanCha == 2 ? 0 : 1));
                sp[columns++]= new SqlParameter("@工单回复内容", zhanDianInfo.ReplyContent);
                sp[columns++]= new SqlParameter("@回复人员", zhanDianInfo.ReplyMan);
                sp[columns++]= new SqlParameter("@物理站点名", zhanDianInfo.PhysicalSite);
                sp[columns++]= new SqlParameter("@工单回复日期", zhanDianInfo.ReplyDate);
                sp[columns++]= new SqlParameter("@后续措施类型", zhanDianInfo.HouXuType);
                sp[columns++]= new SqlParameter("@后续措施编号", zhanDianInfo.HouXuNum);
                sp[columns++]= new SqlParameter("@后续措施所属方案", zhanDianInfo.HouXuFangAn);
                sp[columns++]= new SqlParameter("@后续措施地址", zhanDianInfo.HouXuAddr);
                sp[columns++]= new SqlParameter("@后续措施经度", zhanDianInfo.HouXulongitude);
                sp[columns++]= new SqlParameter("@后续措施纬度", zhanDianInfo.HouXulatitude);
                sp[columns++]= new SqlParameter("@后续措施挂高", zhanDianInfo.HouXuGuaGao);
                sp[columns++]= new SqlParameter("@同意比例", zhanDianInfo.agreeScale);
                sp[columns++]= new SqlParameter("@实际经度", zhanDianInfo.realityLongitude);
                sp[columns++]= new SqlParameter("@实际纬度", zhanDianInfo.realityLatitude);
                sp[columns++] = new SqlParameter("@与规划经纬度偏差距离", zhanDianInfo.howFarToPlanning);
                sp[columns++] = new SqlParameter("@与规划高度偏差", zhanDianInfo.howFarToPlanHeight);
                sp[columns++]= new SqlParameter("@实际高度", zhanDianInfo.realityHeight);
                sp[columns++]= new SqlParameter("@地址", zhanDianInfo.address);
                sp[columns++]= new SqlParameter("@规划方向角", zhanDianInfo.planningFXJiao);
                sp[columns++]= new SqlParameter("@规划配置", zhanDianInfo.planningPZ);
                sp[columns++]= new SqlParameter("@规划机械倾角", zhanDianInfo.planningJXQJiao);
                sp[columns++] = new SqlParameter("@规划电子倾角", zhanDianInfo.planningDZQJiao);

                sp[columns++] = new SqlParameter("@TD工单号_ZD", zhanDianInfo.TDOrderNum);
                sp[columns++] = new SqlParameter("@FK_D_TD是否同意", zhanDianInfo.TDIsAgreeId);
                sp[columns++] = new SqlParameter("@TD是否符合站址偏差标准", zhanDianInfo.TDIsFuHeZhanCha 
                    == 0 ? (int?)null : (zhanDianInfo.TDIsFuHeZhanCha == 2 ? 0 : 1));
                if (zhanDianInfo.TDAgreeScale > 0)
                {
                    sp[columns++] = new SqlParameter("@TD同意比例", zhanDianInfo.TDAgreeScale);
                }
                else
                {
                    sp[columns++] = new SqlParameter("@TD同意比例", (float?)null);
                }
                sp[columns++] = new SqlParameter("@TD工单回复内容", zhanDianInfo.TDReplyContent);
                sp[columns++] = new SqlParameter("@TD规划方向角", zhanDianInfo.TDPlanningFXJiao);
                sp[columns++] = new SqlParameter("@TD规划配置_ZD", zhanDianInfo.TDPlanningPZ);
                sp[columns++] = new SqlParameter("@TD规划机械倾角", zhanDianInfo.TDPlanningJXQJiao);
                sp[columns++] = new SqlParameter("@TD规划电子倾角", zhanDianInfo.TDPlanningDZQJiao);
                sp[columns++] = new SqlParameter("@TD后续措施类型", zhanDianInfo.TDHouXuType);
                sp[columns++] = new SqlParameter("@TD后续措施编号", zhanDianInfo.TDHouXuNum);
                sp[columns++] = new SqlParameter("@TD后续措施所属方案", zhanDianInfo.TDHouXuFangAn);
                sp[columns++] = new SqlParameter("@TD后续措施地址", zhanDianInfo.TDHouXuAddr);
                sp[columns++] = new SqlParameter("@TD后续措施经度", zhanDianInfo.TDHouXulongitude);
                sp[columns++] = new SqlParameter("@TD后续措施纬度", zhanDianInfo.TDHouXulatitude);
                sp[columns++] = new SqlParameter("@TD后续措施挂高", zhanDianInfo.TDHouXuGuaGao);
                sp[columns++] = new SqlParameter("@后续措施相关文号", zhanDianInfo.HouXuFilesNum);
                sp[columns++] = new SqlParameter("@TD后续措施相关文号", zhanDianInfo.TDHouXuFilesNum);
               
            }
         
            sp[columns] = new SqlParameter("@out站点ID", Guid.Empty);
            sp[columns++].Direction = ParameterDirection.Output;
            #endregion
            #region 端口信息
            if (portInfo==null)
            {
                sp[columns++] = new SqlParameter("@端口ID", null);
                sp[columns++] = new SqlParameter("@是否已分配端口", (int?)null);
                sp[columns++] = new SqlParameter("@900M站点申请端口数", (int?)null);
                sp[columns++] = new SqlParameter("@900M站点端口分配数", (int?)null);
                sp[columns++] = new SqlParameter("@900M未完成端口分配原因", null);
                sp[columns++] = new SqlParameter("@900M端口申请日期", null);
                sp[columns++] = new SqlParameter("@1800M站点申请端口数", (int?)null);
                sp[columns++] = new SqlParameter("@1800M站点端口分配数", (int?)null);
                sp[columns++] = new SqlParameter("@1800M未完成端口分配原因", null);
                sp[columns++] = new SqlParameter("@1800M端口申请日期", null);
                sp[columns++] = new SqlParameter("@分配端口总数", (int?)null);
                sp[columns++] = new SqlParameter("@TD站点申请端口数", (int?)null);
                sp[columns++] = new SqlParameter("@TD站点端口分配数", (int?)null);
                sp[columns++] = new SqlParameter("@TD端口申请日期", null);
                sp[columns++] = new SqlParameter("@TD未完成端口分配原因", null);
            } 
            else
            {
                sp[columns++] = new SqlParameter("@端口ID", portInfo.duanKouID);
                sp[columns++] = new SqlParameter("@是否已分配端口", portInfo.isFenpei == 0 ? (int?)null : (portInfo.isFenpei == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@900M站点申请端口数", portInfo._900ShenqingNum);
                sp[columns++] = new SqlParameter("@900M站点端口分配数", portInfo._900FenpeiNum);
                sp[columns++] = new SqlParameter("@900M未完成端口分配原因", portInfo._900Reason);
                sp[columns++] = new SqlParameter("@900M端口申请日期", portInfo._900FenpeiDate);
                sp[columns++] = new SqlParameter("@1800M站点申请端口数", portInfo._1800ShenqingNum);
                sp[columns++] = new SqlParameter("@1800M站点端口分配数", portInfo._1800FenpeiNum);
                sp[columns++] = new SqlParameter("@1800M未完成端口分配原因", portInfo._1800Reason);
                sp[columns++] = new SqlParameter("@1800M端口申请日期", portInfo._1800FenpeiDate);
                sp[columns++] = new SqlParameter("@分配端口总数", portInfo.DuanKouTotalNum);
                sp[columns++] = new SqlParameter("@TD站点申请端口数", portInfo.TDShenqingNum);
                sp[columns++] = new SqlParameter("@TD站点端口分配数", portInfo.TDFenPeiNum);
                sp[columns++] = new SqlParameter("@TD端口申请日期", portInfo.TDShenqingDate);
                sp[columns++] = new SqlParameter("@TD未完成端口分配原因", portInfo.TDReason);
            }
            sp[columns] = new SqlParameter("@out端口ID", Guid.Empty);
            sp[columns++].Direction = ParameterDirection.Output;
            #endregion 
            #region 频率信息
            if (pinLvInfo==null)
            {
                 sp[columns++]  = new SqlParameter("@频率ID", null);
                 sp[columns++] = new SqlParameter("@是否频率申请", (int?)null);
                 sp[columns++] = new SqlParameter("@900M是否频率申请", (int?)null);
                 sp[columns++] = new SqlParameter("@900M是否频率分配", (int?)null);
                 sp[columns++]  = new SqlParameter("@FK_D_900M未分配原因_ID", null);
                 sp[columns++]  = new SqlParameter("@900M频率规划日期", null);
                 sp[columns++]  = new SqlParameter("@900M工单号", null);
                 sp[columns++] = new SqlParameter("@1800M是否频率申请", (int?)null);
                 sp[columns++] = new SqlParameter("@1800M是否频率分配", (int?)null);
                 sp[columns++]  = new SqlParameter("@FK_D_1800M未分配原因_ID", null);
                 sp[columns++]  = new SqlParameter("@1800M频率规划日期", null);
                 sp[columns++]  = new SqlParameter("@1800M工单号", null);
                 sp[columns++] = new SqlParameter("@TD是否频率申请", (int?)null);
                 sp[columns++] = new SqlParameter("@TD是否频率分配", (int?)null);
                 sp[columns++]  = new SqlParameter("@TD频率规划日期", null);
                 sp[columns++] = new SqlParameter("@FK_D_TD未分配原因_ID", null);
                 sp[columns++] = new SqlParameter("@TD工单号", null);
            }
            else
            {
                sp[columns++] = new SqlParameter("@频率ID", pinLvInfo.pinLvID);
                sp[columns++] = new SqlParameter("@是否频率申请", pinLvInfo.isShenqing 
                    == 0 ? (int?)null : (pinLvInfo.isShenqing == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@900M是否频率申请", pinLvInfo.is900Shenqing
                    == 0 ? (int?)null : (pinLvInfo.is900Shenqing == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@900M是否频率分配", pinLvInfo.is900Fenpei
                    == 0 ? (int?)null : (pinLvInfo.is900Fenpei == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@FK_D_900M未分配原因_ID", pinLvInfo._900MReasonID);
                sp[columns++] = new SqlParameter("@900M频率规划日期", pinLvInfo._900GuihuaDate);
                sp[columns++] = new SqlParameter("@900M工单号", pinLvInfo._900Gongdan);
                sp[columns++] = new SqlParameter("@1800M是否频率申请", pinLvInfo.is1800Shenqing
                    == 0 ? (int?)null : (pinLvInfo.is1800Shenqing == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@1800M是否频率分配", pinLvInfo.is1800Fenpei
                    == 0 ? (int?)null : (pinLvInfo.is1800Fenpei == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@FK_D_1800M未分配原因_ID", pinLvInfo._1800MReasonID);
                sp[columns++] = new SqlParameter("@1800M频率规划日期", pinLvInfo._1800GuihuaDate);
                sp[columns++] = new SqlParameter("@1800M工单号", pinLvInfo._1800Gongdan);
                sp[columns++] = new SqlParameter("@TD是否频率申请", pinLvInfo.isTDShengqing
                    == 0 ? (int?)null : (pinLvInfo.isTDShengqing == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@TD是否频率分配", pinLvInfo.isTDFenPei
                    == 0 ? (int?)null : (pinLvInfo.isTDFenPei == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@TD频率规划日期", pinLvInfo.TDGuihuaDate);
                sp[columns++] = new SqlParameter("@FK_D_TD未分配原因_ID", pinLvInfo.TDReasonID);
                sp[columns++] = new SqlParameter("@TD工单号", pinLvInfo.TDGongdanNum);
            }
            sp[columns] = new SqlParameter("@out频率ID", Guid.Empty);
            sp[columns++].Direction = ParameterDirection.Output;
            #endregion
            #region 入网信息
            if (inNetInfo==null)
            {
               
                sp[columns++] = new SqlParameter("@入网ID", null);
                sp[columns++] = new SqlParameter("@物理点入网情况", null);
                sp[columns++] = new SqlParameter("@物理点入网时间", null);
                sp[columns++] = new SqlParameter("@G网站名", null);
                sp[columns++] = new SqlParameter("@D网站名", null);
                sp[columns++] = new SqlParameter("@是否完成规划评估", (int?)null);
                sp[columns++] = new SqlParameter("@是否部分入网", (int?)null);
                sp[columns++] = new SqlParameter("@FK_D_部分入网原因ID", null);
                sp[columns++] = new SqlParameter("@900M入网载频数", (int?)null);
                sp[columns++] = new SqlParameter("@1800M入网载频数", (int?)null);
                sp[columns++] = new SqlParameter("@入网总载频数", (int?)null);
                sp[columns++] = new SqlParameter("@900M入网端口数", (int?)null);
                sp[columns++] = new SqlParameter("@1800M入网端口数", (int?)null);
                sp[columns++] = new SqlParameter("@入网总端口数", (int?)null);
                sp[columns++] = new SqlParameter("@T网站名", null);
                sp[columns++] = new SqlParameter("@TD入网载频数", (int?)null);
                sp[columns++] = new SqlParameter("@TD入网端口数", (int?)null);
                sp[columns++] = new SqlParameter("@部分入网后续跟踪", null);
                sp[columns++] = new SqlParameter("@完成日期", null);
            } 
            else
            {
                sp[columns++] = new SqlParameter("@入网ID", inNetInfo.ruWangID);
                sp[columns++] = new SqlParameter("@物理点入网情况", inNetInfo.RuWangQingKuang);
                sp[columns++] = new SqlParameter("@物理点入网时间", inNetInfo.RuWangDate);
                sp[columns++] = new SqlParameter("@G网站名", inNetInfo.GWangName);
                sp[columns++] = new SqlParameter("@D网站名", inNetInfo.DWangName);
                sp[columns++] = new SqlParameter("@是否完成规划评估", inNetInfo.isComplete == 0 ? (int?)null : (inNetInfo.isComplete == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@是否部分入网", inNetInfo.isRuWang == 0 ? (int?)null : (inNetInfo.isRuWang == 2 ? 0 : 1));
                sp[columns++] = new SqlParameter("@FK_D_部分入网原因ID", inNetInfo.RuWangReasonID);
                sp[columns++] = new SqlParameter("@900M入网载频数", inNetInfo._900ShenqingNum);
                sp[columns++] = new SqlParameter("@1800M入网载频数", inNetInfo._1800ShenqingNum);
                sp[columns++] = new SqlParameter("@入网总载频数", inNetInfo.totalPinNum);
                sp[columns++] = new SqlParameter("@900M入网端口数", inNetInfo._900DuanKouNum);
                sp[columns++] = new SqlParameter("@1800M入网端口数", inNetInfo._1800DuanKouNum);
                sp[columns++] = new SqlParameter("@入网总端口数", inNetInfo.totalDuankouNum);
                sp[columns++] = new SqlParameter("@T网站名", inNetInfo.TWangName);
                sp[columns++] = new SqlParameter("@TD入网载频数", inNetInfo.TDPinNum);
                sp[columns++] = new SqlParameter("@TD入网端口数", inNetInfo.TDDuanKouNum);
                sp[columns++] = new SqlParameter("@部分入网后续跟踪", inNetInfo.TDPartInNetEd);
                sp[columns++] = new SqlParameter("@完成日期", inNetInfo.TDCompleteDate);
            }

            sp[columns] = new SqlParameter("@out入网ID", Guid.Empty);
            sp[columns].Direction = ParameterDirection.Output;
            #endregion

            return sp;
        }
       
        /// <summary>
        /// 编辑网规详细信息，将修改过的网规信息存到记录表
        /// </summary>
        /// <param name="oldNTPlanDetail"></param>
        /// <param name="newNTPlanDetail"></param>
        /// <returns></returns>
        public static bool EditNTPlanDetail(NTPlanDetail oldNTPlanDetail, NTPlanDetail newNTPlanDetail)
        {
            SqlConnection conn = ConnMng.GetConnection();
           
      
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                SqlParameter[] sp = GetNTPlanDetailParams(newNTPlanDetail);
                string commandText = "MTNOH_SH_APP.dbo.mtsp_编辑_网络规划_详细信息";


                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);



                string ruWangId = parameterCollection["@out入网ID"].Value.ToString();
                string pinPvId = parameterCollection["@out频率ID"].Value.ToString();
                string portId = parameterCollection["@out端口ID"].Value.ToString();
                string zhanDianId = parameterCollection["@out站点ID"].Value.ToString();
                if (ruWangId.Length != 0)
                {
                    newNTPlanDetail.inNetInfo.ruWangID = new Guid(ruWangId);
                }
                if (pinPvId.Length != 0)
                {
                   newNTPlanDetail.pinLvInfo.pinLvID = new Guid(pinPvId);
                }
                if (portId.Length != 0)
                {
                    newNTPlanDetail.portInfo.duanKouID = new Guid(portId);
                }
                if (zhanDianId.Length != 0)
                {
                     newNTPlanDetail.zhanDianInfo.zhanDianID = new Guid(zhanDianId);
                }
                OperateLogWrite.AnalysisNTPlanDetail(oldNTPlanDetail, newNTPlanDetail);

                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion
        #region 记录操作日志
        public static void AddOperateLog(LogInfo logInfo)
        {
            if (logInfo.remark.Trim().Length == 0)
            {
                return;
            }
            SqlConnection conn = ConnMng.GetConnection();

            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return;
            }
            try
            {

                string commandText = "MTNOH_SH_APP.dbo.mtsp_新增_操作记录";

                SqlParameter[] sp = new SqlParameter[7];
                sp[0] = new SqlParameter("@FK_规划_ID", logInfo.ntplanID);
                sp[1] = new SqlParameter("@操作人", logInfo.operate);
                sp[2] = new SqlParameter("@时间", logInfo.logTime);
                sp[3] = new SqlParameter("@类别", logInfo.type.ToString());
                sp[4] = new SqlParameter("@操作", logInfo.action.ToString());
                sp[5] = new SqlParameter("@对象ID", logInfo.objID);
                sp[6] = new SqlParameter("@备注", logInfo.remark);

                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);
                return;
            }
            catch
            {
                return;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion
        #region 查询操作日志
        public static DataTable GetOperateLog(Guid guihuaID)
        {
         
            SqlConnection conn = ConnMng.GetConnection();

            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {

                string commandText = "MTNOH_SH_APP.dbo.mtsp_查询_操作历史记录";

                SqlParameter[] sp = new SqlParameter[1];
                sp[0] = new SqlParameter("@规划ID", guihuaID);

                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, commandText, sp);
             
            if (ds!=null)
            {
                return ds.Tables[0];
            }
            return null;
            
            }
            catch
            {
                return null;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 统计_表单
        public static DataTable StatisticNtPlanByType(StatisticsType statisticsType)
        {
            System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString());
            string spName = "";
     
            switch (statisticsType.type)
            {
                case "YiZhanYiDan":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_一站一单确认统计";
                    break;
                case "YiZhanYiDanA":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_一站一单确认统计_分时间";
                    break;
                case "Abis":
                    spName="MTNOH_SH_APP.dbo.mtsp_统计_网络规划_基站ABIS资源申请情况";
                    break;
                case "PinLv":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_基站频率资源申请情况";
                    break;
                case "RuWang":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_新站入网及规划评估情况";
                    break;
                case "BelongScheme":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_按所属方案分类统计";
                    break;

                case "TDYiZhanYiDan":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_TD一站一单确认统计";
                    break;
                case "TDYiZhanYiDanA":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_TD一站一单确认统计_按时间";
                    break;
                case "TDAbis":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_TD基站ABIS资源申请情况";
                    break;
                case "TDPinLv":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_TD基站频率资源申请情况";
                    break;
                case "TDRuWang":
                    spName = "MTNOH_SH_APP.dbo.mtsp_统计_网络规划_TD新站入网及规划评估情况";
                    break;
                default:
                    break;
            }
            if (spName.Length==0)
            {
                return null;
            }
            SqlConnection conn = ConnMng.GetConnection();

            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return null;
            }
            try
            {
                string commandText = spName;

                SqlParameter[] sp = new SqlParameter[6];
                sp[0] = new SqlParameter("@所属方案", statisticsType.belongScheme);
                sp[1] = new SqlParameter("@时间类型", statisticsType.timeType);
                sp[2] = new SqlParameter("@年份", statisticsType.year);
                sp[3] = new SqlParameter("@月份", statisticsType.month);
                sp[4] = new SqlParameter("@开始时间", statisticsType.beginTime);
                sp[5] = new SqlParameter("@结束时间", statisticsType.endTime);
                DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, commandText, sp);

                if (ds != null)
                {
                    return ds.Tables[0];
                }
                return null;

            }
            catch
            {
                return null;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
                System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString());
            }
        }
    #endregion


        #region 根据查询条件导出网规信息的excel
        /// <summary>
        /// 根据查询条件导出网规信息的excel
        /// </summary>
        /// <param name="nTPlanSearchItem"></param>
        /// <returns></returns>
        public static DataTable ExportPlanExcel(NTPlanSearchItem nTPlanSearchItem)
        {
            int totalcount = 0;
            DataTable dt = GetNTPlaningList(nTPlanSearchItem, ref  totalcount);
            return dt;
        
        }
        #endregion

        /// <summary>
        /// 获取导入信息文件模板
        /// </summary>
        /// <returns></returns>
        public static DataTable GetTempletInfo()
        {
        
            //文件夹的路径
            string ObjDirPath = System.Web.HttpContext.Current.Server.MapPath("~") + "templet\\";
            //实例化datatable
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("模板名称", typeof(string)));
            dt.Columns.Add(new DataColumn("大小", typeof(string)));
            dt.Columns.Add(new DataColumn("创建时间", typeof(string)));
            DataRow dr;  //创建dr
            DirectoryInfo SourceDir = new DirectoryInfo(ObjDirPath);
            //循环文件
            foreach (FileSystemInfo FSI in SourceDir.GetFileSystemInfos())
            {
                //读取文件大小
                System.IO.FileStream fsIn = System.IO.File.OpenRead(FSI.FullName);
                dr = dt.NewRow();
                dr[0] = FSI.FullName.Substring(FSI.FullName.LastIndexOf("\\") + 1);
                dr[1] =CommonUtil.GetFileSize(int.Parse(fsIn.Length.ToString()));
                dr[2] = FSI.CreationTime.ToShortDateString();
                dt.Rows.Add(dr);
            }
            return dt;
        }
       

        #region 批量导入
        public static bool ImportZhanDian(ZhanDianInfo zhanDian, ref string retMsg)
        {
            SqlConnection conn = ConnMng.GetConnection();


            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                int columns = 0;
                
                SqlParameter[] sp = new SqlParameter[44];
                sp[columns++] = new SqlParameter("@站点ID", zhanDian.zhanDianID);
                sp[columns] = new SqlParameter("@规划ID", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                sp[columns++] = new SqlParameter("@分公司", zhanDian.company);
                sp[columns++] = new SqlParameter("@2G规划编号", zhanDian.GuihuaID2G);
                sp[columns++] = new SqlParameter("@TD规划编号",zhanDian.GuihuaIDTD);
                sp[columns++] = new SqlParameter("@工单号",zhanDian.orderNum);
                sp[columns++] = new SqlParameter("@实际经度",zhanDian.realityLongitude);
                sp[columns++] = new SqlParameter("@实际纬度" ,zhanDian.realityLatitude);
                sp[columns++] = new SqlParameter("@实际高度",zhanDian.realityHeight);
                sp[columns++] = new SqlParameter("@地址",zhanDian.address);
                sp[columns++] = new SqlParameter("@是否同意",zhanDian.isAgree);
                sp[columns++] = new SqlParameter("@是否符合站址偏差标准",zhanDian.isFuHeZhanCha);
                sp[columns++] = new SqlParameter("@同意比例",zhanDian.agreeScale);
                sp[columns++] = new SqlParameter("@工单回复内容" ,zhanDian.ReplyContent);
                sp[columns++] = new SqlParameter("@规划方向角",zhanDian.planningFXJiao);
                sp[columns++] = new SqlParameter("@规划配置" ,zhanDian.planningPZ);
                sp[columns++] = new SqlParameter("@规划机械倾角",zhanDian.planningJXQJiao);
                sp[columns++] = new SqlParameter("@规划电子倾角" ,zhanDian.planningDZQJiao);
                sp[columns++] = new SqlParameter("@后续措施类型",zhanDian.HouXuType);
                sp[columns++] = new SqlParameter("@后续措施编号", zhanDian.HouXuNum);
                sp[columns++] = new SqlParameter("@后续措施所属方案",zhanDian.HouXuFangAn);
                sp[columns++] = new SqlParameter("@后续措施地址",zhanDian.HouXuAddr);
                sp[columns++] = new SqlParameter("@后续措施经度" ,zhanDian.HouXulongitude);
                sp[columns++] = new SqlParameter("@后续措施纬度" ,zhanDian.HouXulatitude);
                sp[columns++] = new SqlParameter("@后续措施挂高" ,zhanDian.HouXuGuaGao);
                sp[columns++] = new SqlParameter("@TD工单号",zhanDian.TDOrderNum);
                sp[columns++] = new SqlParameter("@TD是否同意" ,zhanDian.TDIsAgree);
                sp[columns++] = new SqlParameter("@TD是否符合站址偏差标准",zhanDian.TDIsFuHeZhanCha);
                sp[columns++] = new SqlParameter("@TD同意比例" ,zhanDian.TDAgreeScale);
                sp[columns++] = new SqlParameter("@TD工单回复内容",zhanDian.TDReplyContent);
                sp[columns++] = new SqlParameter("@TD规划方向角" ,zhanDian.TDPlanningFXJiao);
                sp[columns++] = new SqlParameter("@TD规划配置",zhanDian.TDPlanningPZ);
                sp[columns++] = new SqlParameter("@TD规划机械倾角",zhanDian.TDPlanningJXQJiao);
                sp[columns++] = new SqlParameter("@TD规划电子倾角" ,zhanDian.TDPlanningDZQJiao);
                sp[columns++] = new SqlParameter("@TD后续措施类型",zhanDian.TDHouXuType);
                sp[columns++] = new SqlParameter("@TD后续措施编号", zhanDian.TDHouXuNum);
                sp[columns++] = new SqlParameter("@TD后续措施所属方案",zhanDian.TDHouXuFangAn);
                sp[columns++] = new SqlParameter("@TD后续措施地址",zhanDian.TDHouXuAddr);
                sp[columns++] = new SqlParameter("@TD后续措施经度" ,zhanDian.TDHouXulongitude);
                sp[columns++] = new SqlParameter("@TD后续措施纬度" ,zhanDian.TDHouXulatitude);
                sp[columns++] = new SqlParameter("@TD后续措施挂高" ,zhanDian.TDHouXuGuaGao);
                sp[columns++] = new SqlParameter("@回复人员",operate);
                sp[columns++] = new SqlParameter("@物理站点名",zhanDian.PhysicalSite);
                sp[columns] = new SqlParameter("@outResult", Guid.Empty);
                sp[columns].Direction = ParameterDirection.Output;
                string commandText = "MTNOH_SH_APP.dbo.[mtsp_批量导入_网络规划_站点申请信息]";

                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);
                string zhanDianId = parameterCollection["@outResult"].Value.ToString();
                string guiHuaID = parameterCollection["@规划ID"].Value.ToString();
                if (zhanDianId.Length>0)
                {
                    zhanDian.zhanDianID=new Guid(zhanDianId);
                }
                if (guiHuaID.Length == 0)
                {
                    retMsg = "规划编号不存在";
                    return false;
                }
                zhanDian.guiHuaID = new Guid(guiHuaID);
                OperateLogWrite.LogZhanDianInfo(zhanDian);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
          
        }

        public static bool ImportPort(PortInfo port, ref string retMsg)
        {
        
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
                int columns = 0;
                SqlParameter[] sp = new SqlParameter[19];
                sp[columns++] = new SqlParameter("@端口ID",port.duanKouID);
                sp[columns] = new SqlParameter("@规划ID", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                sp[columns++] = new SqlParameter("@分公司", port.company);
                sp[columns++] = new SqlParameter("@2G规划编号", port.GuihuaID2G);
                sp[columns++] = new SqlParameter("@TD规划编号", port.GuihuaIDTD);
                sp[columns++] = new SqlParameter("@900M站点申请端口数", port._900ShenqingNum);
                sp[columns++] = new SqlParameter("@900M站点端口分配数", port._900FenpeiNum);
                sp[columns++] = new SqlParameter("@900M未完成端口分配原因", port._900Reason);
                sp[columns++] = new SqlParameter("@900M端口申请日期", port._900FenpeiDate);
                sp[columns++] = new SqlParameter("@1800M站点申请端口数",port._1800ShenqingNum);
                sp[columns++] = new SqlParameter("@1800M站点端口分配数", port._1800FenpeiNum);
                sp[columns++] = new SqlParameter("@1800M未完成端口分配原因", port._1800Reason);
                sp[columns++] = new SqlParameter("@1800M端口申请日期", port._1800FenpeiDate);
                sp[columns++] = new SqlParameter("@TD站点申请端口数",port.TDFenPeiNum);
                sp[columns++] = new SqlParameter("@TD站点端口分配数", port.TDFenPeiNum);
                sp[columns++] = new SqlParameter("@TD未完成端口分配原因", port.TDReason);
                sp[columns++] = new SqlParameter("@TD端口申请日期", port.TDShenqingDate);
                sp[columns] = new SqlParameter("@outResult", Guid.Empty);
                sp[columns].Direction = ParameterDirection.Output;
                string commandText = "MTNOH_SH_APP.dbo.[mtsp_批量导入_网络规划_端口申请信息]";
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);
                string portID = parameterCollection["@outResult"].Value.ToString();
                string guiHuaID = parameterCollection["@规划ID"].Value.ToString();
                if (portID.Length > 0)
                {
                    port.duanKouID = new Guid(portID);
                }
                if (guiHuaID.Length==0)
                {
                    retMsg = "规划编号不存在";
                    return false;
                }
                port.guiHuaID = new Guid(guiHuaID);
                OperateLogWrite.LogPortInfo(port);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }

        public static bool ImportPinPv(PinLvInfo pinLv, ref string retMsg)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {

             
                int columns = 0;
                SqlParameter[] sp = new SqlParameter[21];
                sp[columns++] = new SqlParameter("@频率ID", pinLv.pinLvID);
          
                sp[columns] = new SqlParameter("@规划ID", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                sp[columns++] = new SqlParameter("@分公司", pinLv.company);
                sp[columns++] = new SqlParameter("@2G规划编号", pinLv.GuihuaID2G);
                sp[columns++] = new SqlParameter("@TD规划编号", pinLv.GuihuaIDTD);

                sp[columns++] = new SqlParameter("@900M是否频率申请", pinLv.is900Shenqing);
                sp[columns++] = new SqlParameter("@900M是否频率分配", pinLv.is900Fenpei);
                sp[columns++] = new SqlParameter("@900M未分配原因",pinLv._900Reason);
                sp[columns++] = new SqlParameter("@900M频率规划日期", pinLv._900GuihuaDate);
                sp[columns++] = new SqlParameter("@900M工单号", pinLv._900Gongdan);
                sp[columns++] = new SqlParameter("@1800M是否频率申请",pinLv.is1800Shenqing);
                sp[columns++] = new SqlParameter("@1800M是否频率分配", pinLv.is1800Fenpei);
                sp[columns++] = new SqlParameter("@1800M未分配原因", pinLv._1800Reason);
                sp[columns++] = new SqlParameter("@1800M频率规划日期",pinLv._1800GuihuaDate);
                sp[columns++] = new SqlParameter("@1800M工单号", pinLv._1800Gongdan);
                sp[columns++] = new SqlParameter("@TD是否频率申请", pinLv.isTDShengqing);
                sp[columns++] = new SqlParameter("@TD是否频率分配",pinLv.isTDFenPei);
                sp[columns++] = new SqlParameter("@TD频率规划日期", pinLv.TDGuihuaDate);
                sp[columns++] = new SqlParameter("@TD未分配原因", pinLv.TDReason);
                sp[columns++] = new SqlParameter("@TD工单号", pinLv.TDGongdanNum);
                sp[columns] = new SqlParameter("@outResult", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                string commandText = "MTNOH_SH_APP.dbo.[mtsp_批量导入_网络规划_频率申请信息]";
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);
                string pinLvID = parameterCollection["@outResult"].Value.ToString();
                string guiHuaID = parameterCollection["@规划ID"].Value.ToString();
                if (pinLvID.Length > 0)
                {
                    pinLv.pinLvID = new Guid(pinLvID);
                }
                if (guiHuaID.Length == 0)
                {
                    retMsg = "规划编号不存在";
                    return false;
                }
                pinLv.guiHuaID = new Guid(guiHuaID);
                OperateLogWrite.LogPinLvInfo(pinLv);
                
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        public static bool ImportInNet(InNetInfo net, ref string retMsg)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {
              
                int columns = 0;
                SqlParameter[] sp = new SqlParameter[25];
                sp[columns++] = new SqlParameter("@入网ID", net.ruWangID);
                sp[columns] = new SqlParameter("@规划ID", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                sp[columns++] = new SqlParameter("@分公司", net.company);
                sp[columns++] = new SqlParameter("@2G规划编号", net.GuihuaID2G);
                sp[columns++] = new SqlParameter("@TD规划编号", net.GuihuaIDTD);

                sp[columns++] = new SqlParameter("@物理点入网情况", net.RuWangQingKuang);
                sp[columns++] = new SqlParameter("@G网站名", net.GWangName );
                sp[columns++] = new SqlParameter("@D网站名",  net.DWangName );
                sp[columns++] = new SqlParameter("@是否完成规划评估", net.isComplete);
                sp[columns++] = new SqlParameter("@是否部分入网", net.isRuWang);
                sp[columns++] = new SqlParameter("@部分入网原因",net.RuWangReason);
                sp[columns++] = new SqlParameter("@900M入网载频数", net._900ShenqingNum);
                sp[columns++] = new SqlParameter("@1800M入网载频数",  net._1800ShenqingNum);
                sp[columns++] = new SqlParameter("@入网总载频数", net.totalPinNum);
                sp[columns++] = new SqlParameter("@900M入网端口数", net._900DuanKouNum);
                sp[columns++] = new SqlParameter("@1800M入网端口数",  net._1800DuanKouNum);
                sp[columns++] = new SqlParameter("@入网总端口数", net.totalDuankouNum);
                sp[columns++] = new SqlParameter("@T网站名", net.TWangName);
                sp[columns++] = new SqlParameter("@TD入网载频数",net.TDPinNum);
                sp[columns++] = new SqlParameter("@TD入网端口数", net.TDDuanKouNum );
                sp[columns++] = new SqlParameter("@部分入网后续跟踪",net.TDPartInNetEd );
                sp[columns++] = new SqlParameter("@完成日期",net.TDCompleteDate);
                sp[columns] = new SqlParameter("@outResult", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                string commandText = "MTNOH_SH_APP.dbo.[mtsp_批量导入_网络规划_入网申请信息]";
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);
                string intNetId = parameterCollection["@outResult"].Value.ToString();
                string guiHuaID = parameterCollection["@规划ID"].Value.ToString();
                if (intNetId.Length > 0)
                {
                    net.ruWangID = new Guid(intNetId);
                   
                }
                if (guiHuaID.Length==0)
                {
                    retMsg = "规划编号不存在";
                    return false;
                }
                net.guiHuaID = new Guid(guiHuaID);
                OperateLogWrite.LogInNetInfo(net);
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        public static bool ImportNtPlan(NTPlanBase ntPlan)
        {
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return false;
            }
            try
            {

                int columns = 0;
                SqlParameter[] sp = new SqlParameter[22];
                sp[columns] = new SqlParameter("@规划ID", Guid.Empty);
                sp[columns++].Direction = ParameterDirection.Output;
                sp[columns++] = new SqlParameter("@加站属性",ntPlan.jiaZhanPro);
                sp[columns++] = new SqlParameter("@分公司",ntPlan.CompanyName);
                sp[columns++] = new SqlParameter("@所属方案",ntPlan.belongScheme);
                sp[columns++] = new SqlParameter("@TD所属方案",ntPlan.TDBelongScheme);
                sp[columns++] = new SqlParameter("@协同平台工单号",ntPlan.XieTongNum);
                sp[columns++] = new SqlParameter("@是否调整",ntPlan.isTiaoZheng);
                sp[columns++] = new SqlParameter("@是否投诉",ntPlan.isComplaint);
                sp[columns++] = new SqlParameter("@规划编号",ntPlan.planningNum);
                sp[columns++] = new SqlParameter("@TD规划编号",ntPlan.TDPlanningNum);
                sp[columns++] = new SqlParameter("@规划经度",ntPlan.longitude);
                sp[columns++] = new SqlParameter("@规划纬度",ntPlan.latitude);
                sp[columns++] = new SqlParameter("@环线信息",ntPlan.HuanXianInfo);
                sp[columns++] = new SqlParameter("@设备厂商",ntPlan.DeviceFacturer);
                sp[columns++] = new SqlParameter("@规划频段",ntPlan.Channel);
                sp[columns++] = new SqlParameter("@900M规划配置", ntPlan._900PlanPeiZhi);
                sp[columns++] = new SqlParameter("@1800M规划配置", ntPlan._1800PlanPeiZhi);
                sp[columns++] = new SqlParameter("@TD规划配置", ntPlan.TDPlanPeiZhi);
                sp[columns++] = new SqlParameter("@TD配置",ntPlan.TDPeiZhi);
                sp[columns++] = new SqlParameter("@TD规划端口", ntPlan.TDPlanDuanKou);
                sp[columns++] = new SqlParameter("@加站类型",ntPlan.JiaZhanType);
                sp[columns++] = new SqlParameter("@加站目的",ntPlan.jiaZhanAim);
                string commandText = "MTNOH_SH_APP.dbo.[mtsp_批量导入_网络规划_规划信息]";
                SqlParameterCollection parameterCollection = null;
                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, out parameterCollection, sp);
                string guiHuaID = parameterCollection["@规划ID"].Value.ToString();
                if (guiHuaID.Length > 0)
                {
                  
                    ntPlan.ntplanID = new Guid(guiHuaID);
                    OperateLogWrite.LogNTPlanBase(ntPlan);
                    return true;
                }
                return false;
            }
            catch
            {
                return false;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion

        #region 修改用户密码
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="logInID"></param>
        /// <param name="oldPwd"></param>
        /// <param name="newPwd"></param>
        /// <param name="rst">1:成功;0:旧密码错误;</param>
        /// <returns></returns>
        public static int ChangeUserPassword(string logInID, string oldPwd, string newPwd)
        {
            byte[] result1 = Encoding.Default.GetBytes(oldPwd);
            MD5 md51 = new MD5CryptoServiceProvider();
            byte[] output1 = md51.ComputeHash(result1);
            string oldPassword = BitConverter.ToString(output1).Replace("-", "");

            byte[] result2 = Encoding.Default.GetBytes(newPwd);
            MD5 md52 = new MD5CryptoServiceProvider();
            byte[] output2 = md52.ComputeHash(result2);
            string newPassword = BitConverter.ToString(output2).Replace("-", "");

            int rst = -1;
            SqlConnection conn = ConnMng.GetConnection();
            if (conn == null || conn.State != System.Data.ConnectionState.Open)
            {
                return rst;
            }
            try
            {
                string commandText = "MTNOH_SH_APP.dbo.mtsp_修改_用户密码";
                SqlParameter[] sp = new SqlParameter[4];
                sp[0] = new SqlParameter("@outResult", rst);
                sp[0].Direction = ParameterDirection.Output;
                sp[1] = new SqlParameter("@logInID", logInID);
                sp[2] = new SqlParameter("@oldPwd", oldPassword);
                sp[3] = new SqlParameter("@newPwd", newPassword);

                SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, commandText, sp);
                rst = ConvertUtil.StringToInt(sp[0].Value);
                return rst;
            }
            catch
            {
                return rst;
            }
            finally
            {
                ConnMng.ReleaseConnection(conn);
            }
        }
        #endregion
    }
}
